package test
{
	import _Pan3D.display3D.Display3DContainer;
	import _Pan3D.texture.TextureManager;
	
	import _me.Config;
	import _me.KeyControl;
	import _Pan3D.core.MathCore;
	import _me.Scene_data;
	
	import com.adobe.utils.PerspectiveMatrix3D;
	
	import flash.display.MovieClip;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.events.Event;
	
	[SWF(backgroundColor="#FFFFFF",width="1024", height="600", frameRate="60")]
	public class BaseDemo extends MovieClip
	{
		protected var keyControl : KeyControl = new KeyControl();
		protected var projMatrix : PerspectiveMatrix3D;
		protected var container : Display3DContainer;
		
		public function BaseDemo()
		{
			initData();
		}
		protected  function initData():void
		{
			Scene_data.cam3D.distance = 500;
			Scene_data.focus3D.angle_y = -30;
			addEvents()
		}
		protected  function addEvents() : void {
			this.addEventListener(Event.ADDED_TO_STAGE, addToStage);
		}
		protected function addToStage(event : Event) : void {
			Config.init(stage, _config_end);
			keyControl.init(stage);
		}
		protected function  _config_end() : void {
			var context : Context3D = Scene_data.context3D;
			var nn : int = 1024;
			makeScene();
		}
		protected function makeScene():void
		{
			var context : Context3D = Scene_data.context3D;
			TextureManager.getInstance().init(context);
			container=new Display3DContainer;
			this.addEventListener(Event.ENTER_FRAME, enterFrame);
		}
		protected function  enterFrame(event : Event) : void {
			keyControl.upData();
			MathCore._catch_cam(Scene_data.cam3D, Scene_data.focus3D);
			
			if (!Scene_data.ready ) return;
			var context : Context3D = Scene_data.context3D;
			context.clear(0, 0, 0, 1);
			projMatrix = new PerspectiveMatrix3D();
			projMatrix.perspectiveFieldOfViewRH(1, 1, 0.1, 90000);
			context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, projMatrix, true);
			container.update();
			context.present();
			
		}
		
	}
}